#!/bin/bash
# script.sh

function handle_func() {
    echo "handle_func"
}

if [ $# -lt 1 ]; then
    echo "Usage script.sh <daemon_filename>"
    exit 1
fi

daemon_filename=$1

num=0
max=5           # 错误最大出现错误
flag=0
repeat_deny=0   # 判断重复操作
start_time=$(date -d "`date '+%Y%m%d %H:%M:00'`" +%s)
tail -0f ${daemon_filename} | while read i;do
# echo $i
let num=num+1
end_time=$(date -d "`date '+%Y%m%d %H:%M:00'`" +%s)
if [ $start_time -lt $end_time ]; then
    num=0
    if [ $repeat_deny -eq 1 ]; then
        flag=0
    fi
fi
if [ $num -gt $max ] && [ $start_time == $end_time ]; then
    if [ $repeat_deny -eq 1 ]; then
        if [ $flag == 0 ]; then
            echo "一分钟内超过了$max个了"
            handle_func
            # 如果超过最大数目max则把num重置为0
            flag=1
            num=0
        else
            echo "请勿重复操作"
        fi
    else
        echo "一分钟内超过了$max个了"
        handle_func
        # 如果超过最大数目max则把num重置为0
        num=0
    fi

fi

# echo start_time:$start_time
# echo end_time:$end_time
# start_time=$end_time
# echo $num
done
